# coding: utf8
# try something like

utils = local_import('utils')

def __update_urls__(res):
    
    rec_count = 0
    rec_update = 0
    
    for r in res:
        rec_count += 1
        # find the uls in the text        
        urls = utils.find_ulrs(r. text)
        if urls and len(urls) > 0:
            #update the record:
            r.update_record(urls=urls)
            # TODO: how would I update the record?
            rec_update += 1

    return dict(rec_count=rec_count, rec_update=rec_update)



def update_favorite():

    res = db().select(db.twitter_favorite.ALL)
    
    return __update_urls__(res)


def update_usertimeline():

    res = db().select(db.twitter_usertimeline.ALL)
    
    return __update_urls__(res)
